﻿using FastCloud.Base.Config;
using FastCloud.Base.Desgin;
using FastCloud.Base.Entity;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.Base.DB
{
    public class DB_VisitLog : BaseML<Frame_VisitLog>
    {
        public override void Insert(Frame_VisitLog Entity)
        {
            if (string.IsNullOrEmpty(Entity.LogGuid))
            {
                Entity.LogGuid = GenerateUtil.GenerateRowGuid();
            }
            Entity.VisitDateTime = DateTime.Now;
            Entity.VisitDate = DateTime.Now.ToString("yyyy-MM-dd");
            Entity.VisitYear = DateTime.Now.Year;
            Entity.VisitMonth = DateTime.Now.Month;
            Entity.VisitHour = DateTime.Now.Hour;
            Entity.VisitOUGuid = OUGuid;
            Entity.VisitOUName = OUName;
            Entity.VisitUserGuid = UserGuid;
            Entity.VistDisplayName = DisplayName;
            Entity.FromIP = CloudUtil.GetClientIP();
            base.Insert(Entity);
        }

        public override void InsertBatch(List<Frame_VisitLog> EntityList)
        {
            foreach (Frame_VisitLog Entity in EntityList)
            {
                if (string.IsNullOrEmpty(Entity.LogGuid))
                {
                    Entity.LogGuid = GenerateUtil.GenerateRowGuid();
                }
                Entity.VisitDateTime = DateTime.Now;
                Entity.VisitDate = DateTime.Now.ToString("yyyy-MM-dd");
                Entity.VisitYear = DateTime.Now.Year;
                Entity.VisitMonth = DateTime.Now.Month;
                Entity.VisitHour = DateTime.Now.Hour;
                Entity.VisitOUGuid = OUGuid;
                Entity.VisitOUName = OUName;
                Entity.VisitUserGuid = UserGuid;
                Entity.VistDisplayName = DisplayName;
                Entity.FromIP = CloudUtil.GetClientIP();
            }
            base.InsertBatch(EntityList);
        }
    }
}
